package com.xyyl.patient.service.mall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xyyl.patient.core.constant.AppEnum;
import com.xyyl.patient.core.support.Pager;
import com.xyyl.patient.entity.mall.MallOrderInfo;
import com.xyyl.patient.entity.mall.MallOrderRefund;
import com.xyyl.patient.mapper.mall.MallOrderRefundMapper;


/**
* @projectName:xyyl-oms-server
* @ClassName: MallOrderRefund
* @Description:退款管理
* @author @author wqs
* @date 2018-03-05 14:18:16
*/
@Service("MallOrderRefundService")
public class MallOrderRefundServiceImpl implements MallOrderRefundService {

	@Autowired
	private MallOrderRefundMapper MallOrderRefundMapper;
	@Autowired
	private MallOrderInfoService MallOrderInfoService;

	@Override
	public List<MallOrderRefund> queryList(Pager pager) {

		return MallOrderRefundMapper.queryForPage(pager);
	}

	public MallOrderRefund queryObject(Integer id) {
		return MallOrderRefundMapper.selectOne(id);
	}

	@Override
	@Transactional
	public int saveMallOrderRefund(MallOrderRefund MallOrderRefund, MallOrderInfo mallOrderInfo) {
		// 如果存在更新订单状态为退货状态 Pay_status_shipping_customer_service
		mallOrderInfo.setShippingStatus(AppEnum.common.Pay_status_shipping_customer_service.getValue());
		mallOrderInfo.setOrderStatus(AppEnum.common.Order_Refund_status.getValue());
		MallOrderInfoService.updateMallOrderInfo(mallOrderInfo);
		MallOrderRefund.setOrderStatus(AppEnum.common.Order_Refund_status.getValue());// 退货状态
		return MallOrderRefundMapper.insert(MallOrderRefund);
	}

	@Override
	@Transactional
	public int updateMallOrderRefund(MallOrderRefund MallOrderRefund) {
		return MallOrderRefundMapper.update(MallOrderRefund);
	}

	@Override
	@Transactional
	public int deleteMallOrderRefund(Integer id) {
		return MallOrderRefundMapper.delete(id);
	}

	@Override
	@Transactional
	public int batchDeleteMallOrderRefund(Integer[] ids) {

		return 0;
	}

	@Override
	public MallOrderRefund queryByOrderId(Integer orderId) {
		return MallOrderRefundMapper.queryByOrderId(orderId);
	}
}
